package com.ymatou.iapi.login.testcase;

import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.login.parameter.CheckThirdPartyUserIsNeedBindMobileDtoBean;
import com.ymatou.iapi.login.service.CheckThirdPartyUserIsNeedBindMobileDtoCall;
import com.ymatou.iapi.userservice.parameter.UnBindMobileRequestDtoBean;
import com.ymatou.iapi.userservice.parameter.enums.ThirdPartyTypeEnum;
import com.ymatou.iapi.userservice.parameter.req.BindThirdPartyUserReq;
import com.ymatou.iapi.userservice.parameter.req.CreateUserReq;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P3;
import com.ymttest.business.service.JUserCallService;
import com.ymttest.business.service.UserCallService;
import com.ymttest.database.sqlwapper.YmtUsersWapper;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.constant.ECode;
import com.ymttest.utils.constant.ThirdPartyType;


/**
 * 检查第三方账号是否需要绑定手机接口 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_CheckThirdPartyUserIsNeedBindMobileDto {
	private static CheckThirdPartyUserIsNeedBindMobileDtoBean checkthirdpartyuserisneedbindmobiledtoBean;
	private static CheckThirdPartyUserIsNeedBindMobileDtoCall checkthirdpartyuserisneedbindmobiledtoCall;
	private static YmtUsersWapper userWapper;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("检查第三方账号是否需要绑定手机接口");
		userWapper = new YmtUsersWapper();
	}

	@Before
	public void caseUp() {
		checkthirdpartyuserisneedbindmobiledtoBean = new CheckThirdPartyUserIsNeedBindMobileDtoBean();
		checkthirdpartyuserisneedbindmobiledtoCall = new CheckThirdPartyUserIsNeedBindMobileDtoCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(checkthirdpartyuserisneedbindmobiledtoCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CheckThirdPartyUserIsNeedBindMobileDto_001() {
		Logger.start(true, "微博账号已经绑定过手机号码，返回不需要绑定");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			int uid = JUserCallService.createUserCall(cur);
			BindThirdPartyUserReq bd = JUserCallService.initBindThirdUserReq(uid);
			bd.setThirdPartyType(ThirdPartyTypeEnum.Weibo);
			JUserCallService.bindThirdPartyUserCall(bd);
			checkthirdpartyuserisneedbindmobiledtoBean.setThirdPartyId(bd.getThirdPartyId());
			checkthirdpartyuserisneedbindmobiledtoBean.setThirdPartyType(ThirdPartyType.WEIBO);
			checkthirdpartyuserisneedbindmobiledtoCall.setData(checkthirdpartyuserisneedbindmobiledtoBean);
			checkthirdpartyuserisneedbindmobiledtoCall.callService();
			Logger.verifyEquals(ECode.SUCCESS, checkthirdpartyuserisneedbindmobiledtoCall.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals("true", checkthirdpartyuserisneedbindmobiledtoCall.getString("Success"), "验证是否成功");
			Logger.verifyEquals("不需要绑定手机", checkthirdpartyuserisneedbindmobiledtoCall.getString("SuccessMessage"), "验证Msg信息");
			Logger.verifyEquals(ECode.USER_NO, checkthirdpartyuserisneedbindmobiledtoCall.getString("Result"), "验证结果信息");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CheckThirdPartyUserIsNeedBindMobileDto_002() {
		Logger.start(true, "微信账号已经绑定过手机号码，返回不需要绑定");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			int uid = JUserCallService.createUserCall(cur);
			BindThirdPartyUserReq bd = JUserCallService.initBindThirdUserReq(uid);
			bd.setThirdPartyType(ThirdPartyTypeEnum.WeiXin);
			JUserCallService.bindThirdPartyUserCall(bd);
			checkthirdpartyuserisneedbindmobiledtoBean.setThirdPartyId(bd.getThirdPartyId());
			checkthirdpartyuserisneedbindmobiledtoBean.setThirdPartyType(ThirdPartyType.WEIXIN);
			checkthirdpartyuserisneedbindmobiledtoCall.setData(checkthirdpartyuserisneedbindmobiledtoBean);
			checkthirdpartyuserisneedbindmobiledtoCall.callService();
			Logger.verifyEquals(ECode.SUCCESS, checkthirdpartyuserisneedbindmobiledtoCall.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals("true", checkthirdpartyuserisneedbindmobiledtoCall.getString("Success"), "验证是否成功");
			Logger.verifyEquals("不需要绑定手机", checkthirdpartyuserisneedbindmobiledtoCall.getString("SuccessMessage"), "验证Msg信息");
			Logger.verifyEquals(ECode.USER_NO, checkthirdpartyuserisneedbindmobiledtoCall.getString("Result"), "验证结果信息");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CheckThirdPartyUserIsNeedBindMobileDto_003() {
		Logger.start(true, "阿里账号已经绑定过手机号码，返回不需要绑定");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			int uid = JUserCallService.createUserCall(cur);
			BindThirdPartyUserReq bd = JUserCallService.initBindThirdUserReq(uid);
			bd.setThirdPartyType(ThirdPartyTypeEnum.Alipay);
			JUserCallService.bindThirdPartyUserCall(bd);
			checkthirdpartyuserisneedbindmobiledtoBean.setThirdPartyId(bd.getThirdPartyId());
			checkthirdpartyuserisneedbindmobiledtoBean.setThirdPartyType(ThirdPartyType.ALI);
			checkthirdpartyuserisneedbindmobiledtoCall.setData(checkthirdpartyuserisneedbindmobiledtoBean);
			checkthirdpartyuserisneedbindmobiledtoCall.callService();
			Logger.verifyEquals(ECode.SUCCESS, checkthirdpartyuserisneedbindmobiledtoCall.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals("true", checkthirdpartyuserisneedbindmobiledtoCall.getString("Success"), "验证是否成功");
			Logger.verifyEquals("不需要绑定手机", checkthirdpartyuserisneedbindmobiledtoCall.getString("SuccessMessage"), "验证Msg信息");
			Logger.verifyEquals(ECode.USER_NO, checkthirdpartyuserisneedbindmobiledtoCall.getString("Result"), "验证结果信息");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CheckThirdPartyUserIsNeedBindMobileDto_004() {
		Logger.start(false, "微博账号未绑定过手机号码，返回需要绑定");
		try {
			String weiboUser = "NotBind_" + TestDataManager.getRandomNum(10);
			checkthirdpartyuserisneedbindmobiledtoBean.setThirdPartyId(weiboUser);
			checkthirdpartyuserisneedbindmobiledtoBean.setThirdPartyType(ThirdPartyType.WEIBO);
			checkthirdpartyuserisneedbindmobiledtoCall.setData(checkthirdpartyuserisneedbindmobiledtoBean);
			checkthirdpartyuserisneedbindmobiledtoCall.callService();
			Logger.verifyEquals(ECode.ERROR400, checkthirdpartyuserisneedbindmobiledtoCall.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals("true", checkthirdpartyuserisneedbindmobiledtoCall.getString("Success"), "验证是否成功");
			Logger.verifyEquals("需要绑定手机", checkthirdpartyuserisneedbindmobiledtoCall.getString("SuccessMessage"), "验证Msg信息");
			Logger.verifyEquals(ECode.USER_YES, checkthirdpartyuserisneedbindmobiledtoCall.getString("Result"), "验证结果信息");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	@Ignore
	//不存在未绑定账号
	public void Tc_CheckThirdPartyUserIsNeedBindMobileDto_005() {
		Logger.start(false, "微信账号未绑定过手机号码，返回需要绑定");
		try {
			String unionId = "unbindweixin_" + TestDataManager.getRandomNum(10);
			String phone = TestDataManager.getPhoneNum();
			Map user = UserCallService.regByWeiXin(unionId, "", true, null);
			checkthirdpartyuserisneedbindmobiledtoBean.setThirdPartyId(user.get("thirdPartyId").toString());
			checkthirdpartyuserisneedbindmobiledtoBean.setThirdPartyType(ThirdPartyType.WEIXIN);
			checkthirdpartyuserisneedbindmobiledtoCall.setData(checkthirdpartyuserisneedbindmobiledtoBean);
			checkthirdpartyuserisneedbindmobiledtoCall.callService();
			Logger.verifyEquals(ECode.ERROR400, checkthirdpartyuserisneedbindmobiledtoCall.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals("true", checkthirdpartyuserisneedbindmobiledtoCall.getString("Success"), "验证是否成功");
			Logger.verifyEquals("需要绑定手机", checkthirdpartyuserisneedbindmobiledtoCall.getString("SuccessMessage"), "验证Msg信息");
			Logger.verifyEquals(ECode.USER_YES, checkthirdpartyuserisneedbindmobiledtoCall.getString("Result"), "验证结果信息");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CheckThirdPartyUserIsNeedBindMobileDto_006() {
		Logger.start(false, "阿里账号未绑定过手机号码，返回需要绑定");
		try {
			String weiboUser = "NotBind_" + TestDataManager.getRandomNum(4);
			checkthirdpartyuserisneedbindmobiledtoBean.setThirdPartyId(weiboUser);
			checkthirdpartyuserisneedbindmobiledtoBean.setThirdPartyType(ThirdPartyType.ALI);
			checkthirdpartyuserisneedbindmobiledtoCall.setData(checkthirdpartyuserisneedbindmobiledtoBean);
			checkthirdpartyuserisneedbindmobiledtoCall.callService();
			Logger.verifyEquals(ECode.ERROR400, checkthirdpartyuserisneedbindmobiledtoCall.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals("true", checkthirdpartyuserisneedbindmobiledtoCall.getString("Success"), "验证是否成功");
			Logger.verifyEquals("需要绑定手机", checkthirdpartyuserisneedbindmobiledtoCall.getString("SuccessMessage"), "验证Msg信息");
			Logger.verifyEquals(ECode.USER_YES, checkthirdpartyuserisneedbindmobiledtoCall.getString("Result"), "验证结果信息");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_CheckThirdPartyUserIsNeedBindMobileDto_007() {
		Logger.start(false, "未输入第三方账号，检查失败");
		try {
			checkthirdpartyuserisneedbindmobiledtoBean.setThirdPartyType(ThirdPartyType.ALI);
			checkthirdpartyuserisneedbindmobiledtoCall.setData(checkthirdpartyuserisneedbindmobiledtoBean);
			checkthirdpartyuserisneedbindmobiledtoCall.callService();
			Logger.verifyEquals("400", checkthirdpartyuserisneedbindmobiledtoCall.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals("false", checkthirdpartyuserisneedbindmobiledtoCall.getString("Success"), "验证是否成功");
			Logger.verifyIsContains("错误的请求参数|ThirdPartyId不能为空", checkthirdpartyuserisneedbindmobiledtoCall.getString("LastErrorMessage"), "验证Msg信息");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}